﻿using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using TelecoSystems.Infrastructure;
using TelecoSystems.Modules.Dashboard.Views;
using TelecoSystems.Web.Services.Products;

namespace TelecoSystems.Modules.Dashboard
{
    public class DashboardModule : IModule
    {
        private readonly IRegionManager regionManager;
        private readonly IUnityContainer unityContainer;
        private const string MODULE_NAME = "Dashboard";

        public DashboardModule(IRegionManager _regionManager, IUnityContainer _unityContainer)
        {
            regionManager = _regionManager;
            unityContainer = _unityContainer;
        }

        public void Initialize()
        {
            unityContainer.RegisterType<ProductsDomainContext>(new InjectionConstructor());
                        
            IRegion region = regionManager.Regions[RegionNames.MainRegion];
            DashboardModuleView dmView = this.unityContainer.Resolve<DashboardModuleView>();
            region.Add(dmView, dmView.GetType().Name);
            region.Activate(dmView);

            region = regionManager.Regions[MODULE_NAME + RegionNames.ModuleRegion];
            regionManager.RegisterViewWithRegion(MODULE_NAME + RegionNames.ModuleRegion, () => this.unityContainer.Resolve<DashboardView>());
        }

    }
}
